package com.yequan.exesvr.controller;

import com.yequan.mqservice.ExeProducerService;
import com.yequan.pojo.ExeInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yq
 * @date 2020/10/09
 */
@RestController
public class CalculationController {

    @Resource(name = "exeProducerService")
    private ExeProducerService exeProducerService;

    @GetMapping("start")
    public String start() {
        ExeInfo unzipExeInfo1 = new ExeInfo();
        Map<String, String> paramMap1 = new HashMap<>();
        paramMap1.put("jarName", "unzip.jar");
        paramMap1.put("jarPath", "E:\\TEMP\\code\\unzip.jar");
        paramMap1.put("sourceUnzipFilePath", "E:\\TEMP\\4.zip");
        paramMap1.put("targetUnzipPath1", "E:\\TEMP\\nio\\4");
        paramMap1.put("targetUnzipPath2", "E:\\TEMP\\ant\\4");

        unzipExeInfo1.setServiceName("unzipExeHandler")
//                .setExeName("java.exe")
                .setCaseId(1)
                .setCalcType("unzipType")
                .setWsTaskKey("unzip-task1")
                .setUserId(1)
                .setUsername("yq")
                .setExeName("C:\\Program Files\\Java\\jdk1.8.0_65\\bin\\java.exe")
//                .setExeName("D:\\DevelopTool\\java\\jdk1.8\\bin\\java.exe")
                .setLogPath("E:\\TEMP\\log\\unzip-4.log")
                .setParamMap(paramMap1);
        boolean send1 = exeProducerService.send("exe-topic", "*", unzipExeInfo1);
        System.out.println(send1);

        ExeInfo unzipExeInfo2 = new ExeInfo();
        Map<String, String> paramMap2 = new HashMap<>();
        paramMap2.put("jarName", "unzip.jar");
        paramMap2.put("jarPath", "E:\\TEMP\\code\\unzip.jar");
        paramMap2.put("sourceUnzipFilePath", "E:\\TEMP\\4-c.zip");
        paramMap2.put("targetUnzipPath1", "E:\\TEMP\\nio\\4c");
        paramMap2.put("targetUnzipPath2", "E:\\TEMP\\ant\\4c");

        unzipExeInfo2.setServiceName("unzipExeHandler")
//                .setExeName("java.exe")
                .setCaseId(2)
                .setCalcType("unzipType")
                .setWsTaskKey("unzip-task2")
                .setUserId(1)
                .setUsername("yq")
                .setExeName("C:\\Program Files\\Java\\jdk1.8.0_65\\bin\\java.exe")
//                .setExeName("D:\\DevelopTool\\java\\jdk1.8\\bin\\java.exe")
                .setLogPath("E:\\TEMP\\log\\unzip-4-c.log")
                .setParamMap(paramMap2);
        boolean send2 = exeProducerService.send("exe-topic", "*", unzipExeInfo2);
        System.out.println(send2);

        ExeInfo pingExeInfo = new ExeInfo();
        Map<String, String> pingParamMap = new HashMap<>();
        pingParamMap.put("ip", "127.0.0.1");
        pingParamMap.put("n", "-n");
        pingParamMap.put("count", "30");
        pingExeInfo.setServiceName("pingExeHandler")
//                .setExeName("PING.exe")
                .setCaseId(5)
                .setCalcType("pingType")
                .setWsTaskKey("ping-task1")
                .setUserId(1)
                .setUsername("yq")
                .setExeName("C:\\Windows\\System32\\PING.exe")
                .setLogPath("E:\\TEMP\\log\\ping.log")
                .setParamMap(pingParamMap);
        boolean pingSend = exeProducerService.send("exe-topic", "*", pingExeInfo);
        System.out.println(pingSend);
        return "启动成功";
    }

}
